
local locplayer = ac.player.self
local show_update = {}
local show_hide = {}

ac.game:event '游戏-注册显示UI'(function(_,ui,esc_hide)
    show_update[ui] = true
    if esc_hide then
        show_hide[ui] = true
    end
end)


ac.game:event '玩家-刷新UI'(function(_,player)
    if player:is_self() then
        for ui in pairs(show_update) do
            ui:notify('update',ui)
        end
    end
end)


ac.hardware:event '键盘按下'(function(_,key)
    if japi.GetChatState() then
        return
    end
    
    if key=='ESC' then
        ac.game:notify('游戏-按下esc')
        for ui in pairs(show_hide) do
            ui:hide()
        end
    end
    if key=='F2' then
        ac.sync('回城')
    end
    if key=='F3' then
        ac.sync('取消挑战')
    end

    -- if name then
    --     ac.sync(name)
    -- end
    --if code==192 and player.pet then
    --    player:set_camera(player.pet)
    --    player:select_unit(player.pet)
    --end
end)

--处理宽屏
local message = ac.message
if message.client_online then
    local win_w = japi.DzGetWindowWidth()
    local win_h = japi.DzGetWindowHeight()
    if japi.IsWindowMode() then
        local w = math.floor(win_w/16)*16
        local h = math.floor(win_h/9) * 9
        if h/9>w/16 then
            w = h*1920 / 1080
        end
        local x = math.floor((win_w - w) / 2)
        local y = math.floor((win_h - h) / 2)
        japi.SetWindowSize(w,h)
        japi.SetWindowPos(x,y)
        --宽屏
        japi.DzEnableWideScreen(true)
    else
        --japi.SetWindowSize(win_w/0.6,win_h/0.6)
    end
end

-- -- 设置窗口大小
-- function mt.set_window_size(width, height, is_center)
--     if war3_hwnd == 0 then
--         return
--     end
--     if window_flag and not mt.is_zoomed() then
--         width = math.floor(width)
--         height = math.floor(height)
--         if is_center then
--             local x = math.floor((mt.system_window_width() - width) / 2)
--             local y = math.floor((mt.system_window_height() - height) / 2)
--             mt.set_window_pos(x, y, width, height, 4)
--         else
--             mt.set_window_pos(0, 0, width, height, 6)
--         end
--     end
-- end